package com.firstgroup.Utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;

/**
 * 创作人 王箫凯
 * Date 2021/8/9
 * Time 9:15
 *
 * @author 王箫凯
 */
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
public class ResponseResult<T> implements Serializable {
    private T object;
    private Integer code;
    private String message;

    //成功
    public static ResponseResult success(String message, Object object) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.message = message;
        responseResult.code = 200;
        responseResult.object = object;
        return responseResult;
    }

    //成功
    public static ResponseResult success(Object object) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.message = "成功";
        responseResult.object = object;
        responseResult.code = 200;
        return responseResult;
    }

    //失败
    public static ResponseResult error(Integer code, String message) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.message = message;
        responseResult.code = code;
        return responseResult;
    }

    //失败
    public static ResponseResult error(String msg) {
        ResponseResult responseResult = new ResponseResult();
        responseResult.code = 501;
        responseResult.message = msg;
        return responseResult;
    }
}
